<?php /*
	
*/ ?>
<?php include("system/config.inc.php");
$donotinclude = 1;
// IF admin is not logged in then it will redirect to the adminlogin page.
if(!isset($_SESSION['adminuserid']))
{
	header("location:index.php?msg=logfirst");
	die();
}




$action=1;
$proid = $_REQUEST['proid'];

	if(isset($_REQUEST['Submit']) && trim($_REQUEST['Submit']) == "Submit")
	{
			if(isset($_FILES['varthpath']))
			{
				$count=count($_FILES['varthpath']['name']);
				for($i=0;$i<$count;$i++)
				{
					$varImagePath = $_FILES['varthpath']['name'][$i];
					$varbigpath = $_FILES['varthpath']['name'][$i];
					
					$insert="INSERT INTO `tblproimages`  
						(`intprodid`,`varthpath` ,`varbigpath`,`intstatus`)
			  			  VALUES ('$proid','$varImagePath','$varbigpath','1')";
					$sql=$obj_db->insert($insert);
					// get Id of inserted recorde
					$screen_id = mysql_insert_id($obj_db->CONN);
				// Image Uploading			
						$targetpath = "../images/Catalog/";
						$ext=$_FILES['varthpath']['name'][$i];
						$ext=explode(".",$ext);
						if($ext[1]=="jpg" || $ext[1]=="gif" || $ext[1]=="jpeg" || $ext[1]=="png" || $ext[1]=="bmp" || $ext[1]=="wbmp") {	
							if($_FILES['varthpath']['size'][$i] <= 2000000) {
								$filename=$targetpath.$ext[0].$proid.".".$ext[1];
								//echo $filename; 
								$fl_db=$ext[0].$proid.".jpg";
								if(file_exists($filename)) {
									chmod($filename, 0777);
									unlink($filename);
								}
								if(move_uploaded_file($_FILES['varthpath']['tmp_name'][$i],$filename)) {
									$targetpath = "../images/Catalog/th/";
									$file=createThumb($filename , $targetpath , $ext[0].$proid , 80);
									$targetpath = "../images/Catalog/big/";
									$file=createThumb($filename , $targetpath , $ext[0].$proid , 300);
									$sql= "UPDATE tblproimages SET varthpath = '".$fl_db."',
										varbigpath='".$fl_db."'
									 WHERE intid  = '".$screen_id."' ";
									$res=$obj_db->edit($sql);
									header("location:productimages.php?msg=add&proid=$proid");
								} else {
									header("location:productimages.php?proid=$proid");
								}
							}
						}
 				 }		
		}
		header("location:productimages.php?proid=$proid");
		die();
	}
#####################################
// END of INSERTION operation
######################################

	
#####################################
// DELETE record from database
#######################################
if(isset($_REQUEST['a']) && trim($_REQUEST['a'])==3)
{
	if(isset($_REQUEST['intid']) && trim($_REQUEST['intid']!=""))
	{	
		$screen_id =  $_REQUEST['intid'];
		$sql_del = "DELETE FROM tblproimages WHERE intid = '$screen_id'";
		$obj_db->sql_query($sql_del);
		header("location:productimages.php?msg=del");
		die();
	}
}
#####################################
// END of DELETE operation
######################################

?>
<?php include("inc/header.php");?>
<body>
<table width="80%" border="0" align="center" cellpadding="0" cellspacing="1" class="middlebackground">
  <tr>
    <td colspan="3" valign="top" align="center"><?php include(INC."top.inc.php");?></td>
  </tr>
  <tr>
    <td width="2%">&nbsp;</td>
    <td width="95%"><?php   
   if(isset($_REQUEST['script'])) {
	?>
 		<form action="productimages.php?proid=<?php echo $_REQUEST['proid'];?>" method="post" enctype="multipart/form-data" name="manuf">
		
		<table width="60%"  border="0" align="center" cellpadding="2" cellspacing="2" class="border">
          <tr>
		  <td colspan="2" class="bg1">Add New Images...</td>
		  </tr>
		  <tr>
            <td colspan="2" id="otherphoto">
			<table width="100%"  border="0" cellspacing="2" cellpadding="2">                
                <tr>
                  <td align="right" class="sltimg">Select Image :</td>
                  <td align="left"><input name="varthpath[]" type="file" id="varthpath[]"/></td>
                </tr>
            </table></td>
          </tr>
          <tr>
            <td colspan="2" align="center"><input name="Submit" type="submit" value="Submit" class="btn"/>
            </td>
          </tr>
        </table>
		<?php
} else {
?>
        
		<table width="70%" border="0" align="center" cellpadding="2" cellspacing="2" class="border">
          <tr class="bg1">
            <td colspan="3" align="center"><strong>Images...</strong><strong></strong> </td>
            <td width="14%" align="center"><strong><a href="#" title="Click Here to Go Back!" onClick="history.go(-1);" class="fntstyle">Go Back!</a></strong></td>
            <td width="13%" align="center"><strong><a href="productimages.php?script=addproductimages&amp;proid=<?php echo $_REQUEST['proid'];?>" class="new">[New]</a></strong></td>
          </tr>
          <tr class="tblbg3">
            <td width="25%" align="center"><strong>Image</strong></td>
            <td width="22%" align="center"><strong>Product</strong></td>
            <td width="26%" align="center"><strong>Status</strong></td>
            <td colspan="2" align="center"><strong>Delete</strong></td>
          </tr>
          <?php
	   
	   // change status disable or active
if(isset($_REQUEST['status']))
{
	if(isset($_REQUEST['s']) && trim($_REQUEST['s'])==0)
	 {
		if(isset($_REQUEST['imgid']) && trim($_REQUEST['imgid']!=""))
		{
			$id=$_REQUEST['imgid'];
			$proid=$_REQUEST['proid'];
			$update = $obj_db->sql_query("update tblproimages set intstatus = 1 where intid=$id");
			header("location:productimages.php?proid=$proid");
			die();
		}
	}
	if(isset($_REQUEST['s']) && trim($_REQUEST['s'])==1)
	{
		if(isset($_REQUEST['imgid']) && trim($_REQUEST['imgid']!=""))
		{
			$id=$_REQUEST['imgid'];
			$proid=$_REQUEST['proid'];
			$update = $obj_db->sql_query("update tblproimages set intstatus = 0 where intid=$id");
			header("location:productimages.php?proid=$proid");
			die();
		}
	}
}
	   
		$sql="select * from tblproimages where intprodid='".$_REQUEST['proid']."'";
		
		$sql_link=$obj_db->select($sql);
  
   		for($i=0;$i<count($sql_link);$i++)
   		{
            $imagepath = "../images/catalog/th/";
			$limit=$sql_link[$i]['varthpath'];
			$id=$sql_link[$i]['intid'];
			$sql1="select * from tblproddesc where intid ='".$_REQUEST['proid']."'";
			$res=$obj_db->select($sql1);			
    ?>
          <tr class="<?php echo ($i%2==0)?"Hrnormal":"Hralter"; ?>" onMouseOver="this.className='Hrhover';"  onMouseOut="this.className='<?php echo ($i%2==0)?"Hrnormal":"Hralter"; ?>';">
            <td align="center"><img src="<?php echo $imagepath.$sql_link[$i]['varthpath'];?>" width="100" height="100" border="0" /></td>
            <td align="center"><?php echo $res[0]['varprodname'];?></td>
            <td align="center"><table border="0" cellspacing="0" cellpadding="0" align="center">
                <tr>
                  <?php 
					if($sql_link[$i]['intstatus']==0) {
						echo "<td><a class='aa' Title='Click here to Show Image' href='productimages.php?status=0&s=0&imgid=$id&amp;proid=".$_REQUEST['proid']."'>Show</a></td>";		
					}
					if($sql_link[$i]['intstatus']==1) {
						echo "<td><a class='aa' Title='Click here to Hide Image' href='productimages.php?status=1&s=1&imgid=$id&amp;proid=".$_REQUEST['proid']."'>Hide</a></td>";
					}
				?>
                </tr>
            </table></td>
            <td colspan="2" align="center"><a Title="Click here to Delete" href="productimages.php?a=3&amp;intid=<?php echo $id; ?>&amp;proid=<?php echo $_REQUEST['proid'];?>" onClick="return confirm('Are you sure to delete this record?');"><img src="images/delete.bmp" border="0"/></a></td>
          </tr>
          <?php 
		  }
		  
		  ?>
        </table>
<?php }?>
        </form>	</td>
    <td width="3%">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="3"><?php include("inc/bottom.php");?></td>
  </tr>
</table>


